<template>
  <div class="container">
    <!-- 面包屑区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <el-table
        :data="powerlist"
        border
        stripe
        :header-cell-style="henderStyle"
        style="width: 100%">
        <el-table-column
        type="index"
        align="center"></el-table-column>
        <el-table-column
          prop="authName"
          label="权限名称"
          align="center"
          header-align="center">
        </el-table-column>
        <el-table-column
          prop="path"
          label="路径"
          align="center"
          header-align="center">
        </el-table-column>
        <el-table-column
          prop="level"
          label="权限等级"
          align="center"
          header-align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level == 0">一级管理权限</el-tag>
            <el-tag type="success" v-else-if="scope.row.level == 1">二级管理权限</el-tag>
            <el-tag type="warning" v-else>三级管理权限</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'PowerList',
  created () {
    this.getPowerList()
  },
  data () {
    return {
      powerlist: []
    }
  },
  methods: {
    // 获取所有权限列表
    async getPowerList () {
      const { data: res } = await this.$http.get('rights/list')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.powerlist = res.data
    },
    // 设置表头样式
    henderStyle () {
      return 'font-size: 16px;background-color: #F56C6C;color: #fff'
    }
  }
}
</script>

<style lang="less" scoped>
.el-breadcrumb {
    margin-bottom: 12px;
}
</style>
